package org.htp.freemarkerfornetbeans.lexer;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.netbeans.spi.lexer.LanguageHierarchy;
import java.util.Collection;
import org.netbeans.spi.lexer.Lexer;
import org.netbeans.spi.lexer.LexerRestartInfo;

/**
 *
 * @author Artem Pleskatsevich
 */
public class FreeMarkerLanguageHierarchy extends LanguageHierarchy<FreeMarkerTokenId> {

    private static List<FreeMarkerTokenId>  tokens;
    private static Map<Integer,FreeMarkerTokenId>
                                    idToToken;

    private static void init () {
        tokens = FreeMarkerUtils.getTokensList();
        idToToken = new HashMap<Integer, FreeMarkerTokenId> ();
        for (FreeMarkerTokenId token : tokens)
            idToToken.put (token.ordinal (), token);
    }

    static synchronized FreeMarkerTokenId getToken (int id) {
        if (idToToken == null)
            init ();
        return idToToken.get (id);
    }

    protected synchronized Collection<FreeMarkerTokenId> createTokenIds () {
        if (tokens == null)
            init ();
        return tokens;
    }

    protected synchronized Lexer<FreeMarkerTokenId> createLexer (LexerRestartInfo<FreeMarkerTokenId> info) {
        return new FreeMarkerLexer(info);
    }

    protected String mimeType () {
        return "text/x-freemarker";
    }
}
